<?php 
/* 
Proyecto: Sistema Victoria 2.0
Programador: Felipe Guerra
Año: 2015
Flores de tumbabiro ©
*/
$hostname_victoria = "localhost";
$database_victoria = "country";
$username_victoria = "root";
$password_victoria = "";
$victoria = mysql_pconnect($hostname_victoria, $username_victoria, $password_victoria) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_query("SET NAMES 'utf8'");
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script>
$(document).ready(function(e) {
	

	combosDependientes(-1, 1, -1);//envio -1 xq esos parametros no se va a utilizar
	//	combosDependientes(1, 2, 1);
	//	combosDependientes(1, 3, 2);




});

	function combosDependientes(papa, nivel, selected){//papa, nivel a generar, selected(para cargar los datos)
		
		var selectDisabled = '<select disabled="disabled" ><option >Seleccione</option><select>';
		if(nivel == 2){
			$("#select_3").html(selectDisabled);
		}
		
		if(papa == ''){//si selecciona "Seleccione"
			$("#select_" + nivel).html(selectDisabled);
		}		
		
		var sql = '';
		switch(nivel) {
			case 1:
				sql = 'SELECT id AS ID, NAME AS NOMBRE FROM pais WHERE estado = 1 ORDER BY NOMBRE';
				break;
			case 2:
				sql = 'SELECT ID_PROVINCIA AS ID, NOMBRE_PROVINCIA AS NOMBRE FROM provincia WHERE ESTADO = 1 AND ID_PAIS = ' + papa + ' ORDER BY NOMBRE_PROVINCIA';
				break;				
			case 3:
				sql = 'SELECT ID AS ID, NOMBRE_CANTON AS NOMBRE FROM canton WHERE ESTADO = 1 AND ID_PROVINCIA = ' + papa + ' ORDER BY NOMBRE_CANTON';		
				break;
		}		

		ID = papa;		
		if( ID != '' ){
			$.post(
				'comboDependienteAjax.php',
				{ID: ID, nivel: nivel, selected: selected, sql: sql},
				function(data){
					$("#select_" + nivel).html(data);
				}
			);
		}		
		
	}
</script>





<div id="select_1">
</div>

<br><br>

<div id="select_2">
<select disabled="disabled" >
<option >Seleccione</option>
<select>
</div>

<br><br>

<div id="select_3">
<select disabled="disabled" >
<option >Seleccione</option>
<select>
</div>















